import { AnimationClip, AnimationComponent } from 'cc'
import { State } from '../../Base/AnimationState'
import { StateMachine } from '../../Base/StateMachine'
export const enum PLAYER_STATE {
  IDLE_TOP = 'idle_top', //待机状态-上
  IDLE_LEFT = 'idle_left', //待机状态-左
  IDLE_RIGHT = 'idle_right', //待机状态-右
  IDLE_BOTTOM = 'idle_bottom', //待机状态-下
  ATTACK_TOP = 'attack_top', //攻击状态-上
  ATTACK_LEFT = 'attack_left', //攻击状态-左
  ATTACK_RIGHT = 'attack_right', //攻击状态-右
  ATTACK_BOTTOM = 'attack_bottom', //攻击状态-下
  TURNLEFT_TOP = 'turnleft_top', //左转向状态-上
  TURNLEFT_BOTTOM = 'turnleft_bottom', //左转向状态-下
  TURNLEFT_RIGHT = 'turnleft_right', //左转向状态-右
  TURNLEFT_LEFT = 'turnleft_left', //左转向状态-左
  TURNRIGHT_TOP = 'turnright_top', //右转向状态-上
  TURNRIGHT_BOTTOM = 'turnright_bottom', //右转向状态-下
  TURNRIGHT_RIGHT = 'turnright_right', //右转向状态-右
  TURNRIGHT_LEFT = 'turnright_left', //右转向状态-左
  DEATH_TOP = 'death_top', //死亡状态-上
  DEATH_BOTTOM = 'death_bottom', //死亡状态-下
  DEATH_RIGHT = 'death_right', //死亡状态-右
  DEATH_LEFT = 'death_left', //死亡状态-左
  AIRDEATH_TOP = 'airdeath_top', //空中死亡状态-上
  AIRDEATH_BOTTOM = 'airdeath_bottom', //空中死亡状态-下
  AIRDEATH_RIGHT = 'airdeath_right', //空中死亡状态-右
  AIRDEATH_LEFT = 'airdeath_left', //空中死亡状态-左
  BLOCKBACK_TOP = 'blockback_top', //后退被阻挡状态-上
  BLOCKBACK_BOTTOM = 'blockback_bottom', //后退被阻挡状态-下
  BLOCKBACK_RIGHT = 'blockback_right', //后退被阻挡状态-右
  BLOCKBACK_LEFT = 'blockback_left', //后退被阻挡状态-左
  BLOCKFRONT_TOP = 'blockfront_top', //前进被阻挡状态-上
  BLOCKFRONT_BOTTOM = 'blockfront_bottom', //前进被阻挡状态-下
  BLOCKFRONT_RIGHT = 'blockfront_right', //前进被阻挡状态-右
  BLOCKFRONT_LEFT = 'blockfront_left', //前进被阻挡状态-左
  BLOCKLEFT_TOP = 'blockleft_top', //左移被阻挡状态-上
  BLOCKLEFT_BOTTOM = 'blockleft_bottom', //左移被阻挡状态-下
  BLOCKLEFT_RIGHT = 'blockleft_right', //左移被阻挡状态-右
  BLOCKLEFT_LEFT = 'blockleft_left', //左移被阻挡状态-左
  BLOCKRIGHT_TOP = 'blockright_top', //右移被阻挡状态-上
  BLOCKRIGHT_BOTTOM = 'blockright_bottom', //右移被阻挡状态-下
  BLOCKRIGHT_RIGHT = 'blockright_right', //右移被阻挡状态-右
  BLOCKRIGHT_LEFT = 'blockright_left', //右移被阻挡状态-左
  BLOCKTURNLEFT_TOP = 'blockturnleft_top', //左转被阻挡状态-上
  BLOCKTURNLEFT_BOTTOM = 'blockturnleft_bottom', //左转被阻挡状态-下
  BLOCKTURNLEFT_RIGHT = 'blockturnleft_right', //左转被阻挡状态-右
  BLOCKTURNLEFT_LEFT = 'blockturnleft_left', //左转被阻挡状态-左
  BLOCKTURNRIGHT_TOP = 'blockturnright_top', //右转被阻挡状态-上
  BLOCKTURNRIGHT_BOTTOM = 'blockturnright_bottom', //右转被阻挡状态-下
  BLOCKTURNRIGHT_RIGHT = 'blockturnright_right', //右转被阻挡状态-右
  BLOCKTURNRIGHT_LEFT = 'blockturnright_left', //右转被阻挡状态-左

  MOVE = 'move', //移动状态
}
export class PlayerStateMachine extends StateMachine<PLAYER_STATE> {
  constructor(private _animationComponent: AnimationComponent) {
    super()
    this.initStateMap()
  }
  //初始化状态集合
  initStateMap() {
    const speed = 1 / 8
    const { Loop } = AnimationClip.WrapMode
    const acp = this._animationComponent
    const idleBaseUrl = 'texture/player/idle'
    const attackBaseUrl = 'texture/player/attack'
    const turnLeftBaseUrl = 'texture/player/turnleft'
    const turnRightBaseUrl = 'texture/player/turnright'
    const deadBaseUrl = 'texture/player/death'
    const airDeathBaseUrl = 'texture/player/airdeath'
    const blockBackBaseUrl = 'texture/player/blockback'
    const blockFrontBaseUrl = 'texture/player/blockfront'
    const blockLeftBaseUrl = 'texture/player/blockleft'
    const blockRightBaseUrl = 'texture/player/blockright'
    const blockTurnLeftBaseUrl = 'texture/player/blockturnleft'
    const blockTurnRightBaseUrl = 'texture/player/blockturnright'
    //待机
    this.addState(PLAYER_STATE.IDLE_TOP, new State(acp, `${idleBaseUrl}/top/idle`, speed, Loop))
    this.addState(PLAYER_STATE.IDLE_LEFT, new State(acp, `${idleBaseUrl}/left/idle`, speed, Loop))
    this.addState(PLAYER_STATE.IDLE_RIGHT, new State(acp, `${idleBaseUrl}/right/idle`, speed, Loop))
    this.addState(PLAYER_STATE.IDLE_BOTTOM, new State(acp, `${idleBaseUrl}/bottom/idle`, speed, Loop))

    //攻击
    this.addState(PLAYER_STATE.ATTACK_TOP, new State(acp, `${attackBaseUrl}/top/attack`))
    this.addState(PLAYER_STATE.ATTACK_LEFT, new State(acp, `${attackBaseUrl}/left/attack`))
    this.addState(PLAYER_STATE.ATTACK_RIGHT, new State(acp, `${attackBaseUrl}/right/attack`))
    this.addState(PLAYER_STATE.ATTACK_BOTTOM, new State(acp, `${attackBaseUrl}/bottom/attack`))

    //左转向
    this.addState(PLAYER_STATE.TURNLEFT_TOP, new State(acp, `${turnLeftBaseUrl}/top/turnleft`))
    this.addState(PLAYER_STATE.TURNLEFT_LEFT, new State(acp, `${turnLeftBaseUrl}/left/turnleft`))
    this.addState(PLAYER_STATE.TURNLEFT_RIGHT, new State(acp, `${turnLeftBaseUrl}/right/turnleft`))
    this.addState(PLAYER_STATE.TURNLEFT_BOTTOM, new State(acp, `${turnLeftBaseUrl}/bottom/turnleft`))

    //右转向
    this.addState(PLAYER_STATE.TURNRIGHT_TOP, new State(acp, `${turnRightBaseUrl}/top/turnright`))
    this.addState(PLAYER_STATE.TURNRIGHT_LEFT, new State(acp, `${turnRightBaseUrl}/left/turnright`))
    this.addState(PLAYER_STATE.TURNRIGHT_RIGHT, new State(acp, `${turnRightBaseUrl}/right/turnright`))
    this.addState(PLAYER_STATE.TURNRIGHT_BOTTOM, new State(acp, `${turnRightBaseUrl}/bottom/turnright`))

    //死亡
    this.addState(PLAYER_STATE.DEATH_TOP, new State(acp, `${deadBaseUrl}/top/death`))
    this.addState(PLAYER_STATE.DEATH_LEFT, new State(acp, `${deadBaseUrl}/left/death`))
    this.addState(PLAYER_STATE.DEATH_RIGHT, new State(acp, `${deadBaseUrl}/right/death`))
    this.addState(PLAYER_STATE.DEATH_BOTTOM, new State(acp, `${deadBaseUrl}/bottom/death`))

    //空中死亡
    this.addState(PLAYER_STATE.AIRDEATH_TOP, new State(acp, `${airDeathBaseUrl}/top/death`))
    this.addState(PLAYER_STATE.AIRDEATH_LEFT, new State(acp, `${airDeathBaseUrl}/left/death`))
    this.addState(PLAYER_STATE.AIRDEATH_RIGHT, new State(acp, `${airDeathBaseUrl}/right/death`))
    this.addState(PLAYER_STATE.AIRDEATH_BOTTOM, new State(acp, `${airDeathBaseUrl}/bottom/death`))

    //后退被阻挡
    this.addState(PLAYER_STATE.BLOCKBACK_TOP, new State(acp, `${blockBackBaseUrl}/top/blockback`))
    this.addState(PLAYER_STATE.BLOCKBACK_LEFT, new State(acp, `${blockBackBaseUrl}/left/blockback`))
    this.addState(PLAYER_STATE.BLOCKBACK_RIGHT, new State(acp, `${blockBackBaseUrl}/right/blockback`))
    this.addState(PLAYER_STATE.BLOCKBACK_BOTTOM, new State(acp, `${blockBackBaseUrl}/bottom/blockback`))

    //前进被阻挡
    this.addState(PLAYER_STATE.BLOCKFRONT_TOP, new State(acp, `${blockFrontBaseUrl}/top/blockfront`))
    this.addState(PLAYER_STATE.BLOCKFRONT_LEFT, new State(acp, `${blockFrontBaseUrl}/left/blockfront`))
    this.addState(PLAYER_STATE.BLOCKFRONT_RIGHT, new State(acp, `${blockFrontBaseUrl}/right/blockfront`))
    this.addState(PLAYER_STATE.BLOCKFRONT_BOTTOM, new State(acp, `${blockFrontBaseUrl}/bottom/blockfront`))

    //左移被阻挡
    this.addState(PLAYER_STATE.BLOCKLEFT_TOP, new State(acp, `${blockLeftBaseUrl}/top/blockleft`))
    this.addState(PLAYER_STATE.BLOCKLEFT_LEFT, new State(acp, `${blockLeftBaseUrl}/left/blockleft`))
    this.addState(PLAYER_STATE.BLOCKLEFT_RIGHT, new State(acp, `${blockLeftBaseUrl}/right/blockleft`))
    this.addState(PLAYER_STATE.BLOCKLEFT_BOTTOM, new State(acp, `${blockLeftBaseUrl}/bottom/blockleft`))

    //右移被阻挡
    this.addState(PLAYER_STATE.BLOCKRIGHT_TOP, new State(acp, `${blockRightBaseUrl}/top/blockright`))
    this.addState(PLAYER_STATE.BLOCKRIGHT_LEFT, new State(acp, `${blockRightBaseUrl}/left/blockright`))
    this.addState(PLAYER_STATE.BLOCKRIGHT_RIGHT, new State(acp, `${blockRightBaseUrl}/right/blockright`))
    this.addState(PLAYER_STATE.BLOCKRIGHT_BOTTOM, new State(acp, `${blockRightBaseUrl}/bottom/blockright`))

    //左转被阻挡
    this.addState(PLAYER_STATE.BLOCKTURNLEFT_TOP, new State(acp, `${blockTurnLeftBaseUrl}/top/blockturnleft`))
    this.addState(PLAYER_STATE.BLOCKTURNLEFT_LEFT, new State(acp, `${blockTurnLeftBaseUrl}/left/blockturnleft`))
    this.addState(PLAYER_STATE.BLOCKTURNLEFT_RIGHT, new State(acp, `${blockTurnLeftBaseUrl}/right/blockturnleft`))
    this.addState(PLAYER_STATE.BLOCKTURNLEFT_BOTTOM, new State(acp, `${blockTurnLeftBaseUrl}/bottom/blockturnleft`))

    //右转被阻挡
    this.addState(PLAYER_STATE.BLOCKTURNRIGHT_TOP, new State(acp, `${blockTurnRightBaseUrl}/top/blockturnright`))
    this.addState(PLAYER_STATE.BLOCKTURNRIGHT_LEFT, new State(acp, `${blockTurnRightBaseUrl}/left/blockturnright`))
    this.addState(PLAYER_STATE.BLOCKTURNRIGHT_RIGHT, new State(acp, `${blockTurnRightBaseUrl}/right/blockturnright`))
    this.addState(PLAYER_STATE.BLOCKTURNRIGHT_BOTTOM, new State(acp, `${blockTurnRightBaseUrl}/bottom/blockturnright`))
  }
}
